package com.learn.base.exception;

import com.learn.base.model.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author : Yu.Tan
 * @date : 2023/1/17 18:09
 * @desc : **
 */
@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public BaseResponse handleRRException(BusinessException e) {
        BaseResponse r = new BaseResponse<>();
        r.setCode(e.getHttpStatusCode());
        r.setMessage(e.getMessage());
        return r;
    }
}
